package cn.wk.servlet;

import cn.wk.entity.Classes;
import cn.wk.entity.Course;
import cn.wk.services.ClassesServices;
import cn.wk.services.CourseServices;
import cn.wk.services.impl.Classesserviceslmpl;
import cn.wk.services.impl.CourseServicesImpl;
import cn.wk.util.ConvertUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/courseShow")
public class ServletcourseShow extends HttpServlet {
    private static CourseServices a=new CourseServicesImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        int page =Integer.parseInt(request.getParameter("page"));
        int limit =Integer.parseInt(request.getParameter("limit"));
        List<Course> list=a.getAllCourse((page-1)*limit,limit);
        int count=a.CountSize();
        String str= ConvertUtil.ConvertPageJson(list,count);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println(str);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
